package algorithm.leetcode;

/**
 * @program: util
 * @description: 盛最多水的容器
 * @author: zhouliangliang
 * @create: 2021-04-06 15:08
 **/
public class WaterContainer {

    //min(array[i],array[j])*(j-i)
    private int test(int []array) {
        int i = 0;
        int j = array.length - 1;
        int valume = 0;
        while (i<j) {
            int left = array[i];
            int right = array[j];
            int temp = (j - i) * Math.min(left, right);
            valume = valume > temp ? valume : temp;
            if(array[i] < array[j]) {
                i = i+1;
            } else {
                j = j-1;
            }
        }
        return valume;
    }

    public static void main(String[] args) {
        int[] array1  = new int[]{1,8,7,9,4,6,2,5};
        int[] array2 = new int[]{1,8,6,2,5,4,8,3,7};
        new WaterContainer().test(array1);
        new WaterContainer().test(array2);
    }

}
